<template>
  <div class="detail" style="background-color: #f7f7f7;">
    <van-nav-bar
      title="病历夹详情"
      left-text=""
      left-arrow
      @click-left="
        $router.push({
          path: '/jiankang',
        })
      "
    />
    <van-field v-model="Keshi" type="text" label="问诊科室" />
    <van-field v-model="userDetail.time" type="text" label="问诊时间" />
    <van-field v-model="userDetail.name" type="text" label="问诊姓名" />
    <van-field v-model="nameMu" type="number" label="问诊备注" />
    <button
      style="
        width: 90%;
        margin-left: 20px;
        border-radius: 25px;
        border: none;
        background-color: white;
        color: #ffa990;
        height: 50px;
        position: absolute;
        top: 300px;
      "
      @click="handleDelete(userDetail.id)"
    >
      删除
    </button>
  </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { showNotify } from 'vant'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
import { showToast } from 'vant';
const id = ref(route.query.item as string)
console.log(id.value)
const userDetail = ref<any>({})
import { showConfirmDialog } from 'vant';
const Detail = async () => {
  await axios
    .get('/addres/BingLi', {
      params: {
        id: id.value,
      },
    })
    .then((res) => {
      console.log(res)
      userDetail.value = res.data.data
      console.log(userDetail.value)
    })
    
}
Detail()

const handleDelete = (id: string) => {

  axios
    .delete('/addres/BingLiDelete', {
      params: {
        id: id,
      },
    })
    .then((res) => {
      console.log(res)
      showToast({
  message: '删除成功',
  icon: 'success',
});
      if (res.data.code === 200) {
        showConfirmDialog({
  message:
    '确认要删除病历本？',
}).then(() => {
       showToast({
  message: '删除成功',
  icon: 'success',
});
}).catch(() => {})


        userDetail.value = {}
      }
    })
    
}
</script>
